﻿using QuickCode.Domain.Entity;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;

namespace MySqlSugar.Context
{
    public class SqlSugarContext
    {
        public readonly ISqlSugarClient db;
        public SqlSugarContext(ISqlSugarClient DBContext)
        {
            this.db = DBContext;
        }

        public void CreateTable()
        {
            db.DbMaintenance.CreateDatabase();//没有数据库则新建
            db.CodeFirst.SetStringDefaultLength(50).BackupTable().InitTables(new Type[]
            {
                typeof(test)                     //根据test实体创建表
            });
        }

        /// <summary>
        /// //参数1：路径  参数2：命名空间
        //IsCreateAttribute 代表生成SqlSugar特性
        /// </summary>
        public void CreateClassFile(string path,string spacename)
        {
            db.DbFirst.IsCreateAttribute().CreateClassFile(path, spacename);
        }
    }
}
